package com.shiguo365.market.display.activity;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.ActionBar;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.Toast;

import com.recker.flybanner.FlyBanner;
import com.shiguo365.market.display.base.BaseActivity;
import com.shiguo365.market.display.util.ActivityCollector;
import com.shiguo365.market.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by caomenglong on 16/7/8.
 */
public class DetailActivity extends BaseActivity {
    private FlyBanner mBannerNet;//加载网络图片
    private WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        initNetBanner();
        webView = (WebView) findViewById(R.id.webViewdetail);

        ActionBar actionBar = getSupportActionBar();
        if(actionBar == null){
            toast("空指针");
        }else{
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        ActivityCollector.addActivity(this);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActivity(this);
    }


    /**
     * 加载网页图片
     */
    private void initNetBanner() {
        mBannerNet = (FlyBanner) findViewById(R.id.detailbanner);

        String[] mImagesUrl = {
                "http://7xj380.com1.z0.glb.clouddn.com/2016-07-03_5778d0726ac00.png",
                "http://7xj380.com1.z0.glb.clouddn.com/2016-07-03_5778d43571e6e.png",
                "http://7xj380.com1.z0.glb.clouddn.com/2016-07-03_5778e8177ea01.png",
                "http://7xj380.com1.z0.glb.clouddn.com/2016-06-30_577479528ff61.png"
        };

        List<String> imgesUrl = new ArrayList<>();
        for (int i = 0; i < mImagesUrl.length; i++) {
            imgesUrl.add(mImagesUrl[i]);
        }
        mBannerNet.setImagesUrl(imgesUrl);

        mBannerNet.setOnItemClickListener(new FlyBanner.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                toast("点击了第" + position + "张图片");
            }
        });
    }

    private void toast(String str) {
        Toast.makeText(DetailActivity.this, str, Toast.LENGTH_SHORT).show();
    }
}
